<%@ page import="dao.UserDao" %>
<%@ page import="bean.ShopBean" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
		 pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Shop</title>
		<script src="${pageContext.request.contextPath}/js/js/popper.min.js"></script>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/js/css/bootstrap.min.css">
		<!-- 最新的 Bootstrap5 核心 JavaScript 文件 -->
		<script src="${pageContext.request.contextPath}/js/js/bootstrap.min.js"></script>
		
	</head>
	<body style="background: antiquewhite">
		<div class="container">
			<div  class = "col-md-12 column col-md-offset-4 col-lg-offset-4col-xl-offset-4">
				<img  style="margin: auto;" src="./img/rebrand_shopbop_logo_2x_1-3.png"/>
			</div>
			<!--导航栏-->
			<div class="col-md-12 column">
				<ul class="nav">
					<li class="nav-item">
						<a  href="javascript:location.reload();" class="nav-link" >ShopBop</a>
					</li>
					<li class="nav-item">
						<a target="_blank" href="./manage.jsp" class="btn btn-primary">返回</a>
					</li>

				</ul>
			</div>
				
		
				<!--
				
				实现装商品的盘子
				-->
				
			<div class="col-md-12 column">
			<%
				ShopBean shop;
				String id;
				int a=3;
				String dell=(String) request.getSession().getAttribute("del");
				if(dell==null){
					id=request.getParameter("id");
					if(id==null){
						id=(String) request.getSession().getAttribute("id");
					}
					shop = new UserDao().showShopById(id);
				}else{

					id=request.getParameter("id");
					if(id==null){
						id=(String) request.getSession().getAttribute("id");
					}
					shop = new UserDao().showShopById(id);
					if(shop==null){

					}else{
						a=new UserDao().delShop(id);
						request.getSession().removeAttribute("del");
					}


				}






			%>

			<div class="row">
				<div class="col-md-4">
					<img style="width: 300px;height: 300px" src="./images/<%=shop.getPath()%>">
			</div>
				
				<div class="col-md-4">
					<form onsubmit="return check()" role="form" enctype="multipart/form-data" action="${pageContext.request.contextPath}/UpdateServlet" method="POST">
									<div class="form-group">
										 <label for="name">商品名称</label><input type="text" value="<%=shop.getName()%>" name="name" class="form-control" id="name" />
									</div>
									<div class="form-group">
										 <label for="contenct">商品描述</label><input type="text"  value="<%=shop.getContenct()%>" name="contenct" class="form-control" id="contenct" />
									</div>

									<div class="form-group">
										 <label for="price">价格</label><input type="text" name="price" value="<%=shop.getPrice()%>"  class="form-control" id="price" />
									</div>

						<input type="hidden" name="id" value="<%=shop.getId()%>"  class="form-control" />
									<div class="form-group">
										 <label for="exampleInputFile">选择图片</label>
										<input type="file" id="exampleInputFile" name="filename"/>

									</div>
								
									<button type="submit" class="btn btn-danger">更改商品</button>

									<a id="delc" href="${pageContext.request.contextPath}/DelShopServlet?id=<%=shop.getId()%>" class="btn btn-danger">删除商品</a>
									<%if(a==0){%>

									<label>删除失败</label>
									<%}if(a==1){%>
						<script >
							document.getElementById("delc").remove()


						</script>
									<label>删除成功</label>
						<%}%>

									${message}
								</form>
					
			</div>	
		</div>	
					
			
				
					
		
				</div>
			</div>
				
			
			</div>
		</div>
		
		
		
		
	</body>
<script>
	function  check(){

		var name = document.getElementById('name').value
		var contenct = document.getElementById('contenct').value
		var discount = document.getElementById('discount').value
		var price = document.getElementById('price').value


		if(name==""){
			alert("请输入名字")
			return false
		}else if(contenct==""){
			alert("请输入内容")
		}else if(discount==""){
			alert("请输入折扣")
		}else if(price==""){
			alert("请输入价格")
		}else{
			return true
		}

	}

	

</script>
</html>
